package cease.butter;

import java.util.LinkedList;
import java.util.List;

import net.sf.json.JSON;

import org.apache.commons.lang.StringUtils;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import cease.urs.Session;
import cease.vo.UserInfo;

/**
 * @author dhf
 */
public class BlockExecutor extends BaseExecutor {
    private static BlockExecutor executor = new BlockExecutor();

    public static BlockExecutor getInstance() {
        return executor;
    }

    public UserInfo block(Session session, String user) throws ApiException {
        if (StringUtils.isBlank(user)) {
            throw new IllegalArgumentException("[user] could not be null");
        }

        List<NameValuePair> pairs = new LinkedList<NameValuePair>();
        pairs.add(new BasicNameValuePair("id", user));
        JSON json = post(Constants.URL_BLOCK_ADD, pairs, null, session);
        return toUserInfo(json);
    }

    public UserInfo unblock(Session session, String user) throws ApiException {
        if (StringUtils.isBlank(user)) {
            throw new IllegalArgumentException("[user] could not be null");
        }

        List<NameValuePair> pairs = new LinkedList<NameValuePair>();
        pairs.add(new BasicNameValuePair("id", user));
        JSON json = post(Constants.URL_BLOCK_DELETE, pairs, null, session);
        return toUserInfo(json);
    }

    public UserInfo check(Session session, String user) throws ApiException {
        if (StringUtils.isBlank(user)) {
            throw new IllegalArgumentException("[user] could not be null");
        }

        List<NameValuePair> pairs = new LinkedList<NameValuePair>();
        pairs.add(new BasicNameValuePair("id", user));
        JSON json = post(Constants.URL_BLOCK_CHECK, pairs, null, session);
        return toUserInfo(json);
    }
}
